$(document).ready(function(){

var root = this;

// Header menu
$('.menu').children().each(function() {
  var $self = $(this);
  var menuItemLabel = $self.children('a').text().toLowerCase();

  // Cache a var for the menu items
  root['$' + menuItemLabel + 'MenuItem'] = $self;
});

if ($('body').hasClass('single-features')) {
  $featuresMenuItem.addClass('current-menu-ancestor');
}

if (document.location.href.match(/(case-studies)/)) {
  $resourcesMenuItem.addClass('current-menu-ancestor');
}

// Dropdowns
$('.menu-item').on({
  mouseover: function() {
    var $self    = $(this);
    var $subMenu = $self.find('.sub-menu');

    // Check if the hovered element contains a dropdown
    if ($subMenu.lenght) return;

    $subMenu.fadeIn(100);
  },

  mouseleave: function() {
    var $self    = $(this);
    var $subMenu = $self.find('.sub-menu');

    $subMenu.fadeOut(200);
  }
});

// Laptop slideshow
$('.screenshots').cycle({
  fx: 'fade',
  speed: 500
});

// Contact Forms
var placeholders = {}
$('.placeholder').each(function () {
    var $self = $(this);
    placeholders[$self.attr("name")] = $self.val();

    $self.attr('placeholder', $self.val()).removeClass('placeholder').val('');
}).focus(function () {
    var $self = $(this);

    if ($self.val() == $self.attr('placeholder')) {
        $self.removeClass('placeholder').val('');
    }
}).blur(function () {
    var $self = $(this);
    var value = $self.val();
    var placeholder = placeholders[$self.attr("name")];

    if (value == '' || value == placeholder) {
        $self.val(placeholder).addClass('placeholder');
    }
}).blur();

// Fancy box
$("a[rel=example_group]").fancybox({
	'transitionIn'	:	'elastic',
	'transitionOut'	:	'elastic',
	'speedIn'		:	600, 
	'speedOut'		:	200, 
	'overlayShow'	:	true
});	

$("#online_support_template").live('click', function()
{
	if ($(this).attr('status') == 'hide')
	{
		$("#online_support").animate(
			{ bottom: '+=420' }, 
			{ duration: 500, 
			  specialEasing: 
				{
					width: 'linear',
					height: 'easeOutBounce'
				}
		});
		$(this).attr('status', 'show');
		$('#plus_button').removeClass("plus_button_to_plus");
		$('#plus_button').addClass("plus_button_to_sub");
	}
	else
	{
		$("#online_support").animate(
			{ bottom: '-420px' }, 
			{ duration: 100 }
		);
		$(this).attr('status', 'hide');
		$('#plus_button').removeClass('plus_button_to_sub');
		$('#plus_button').addClass("plus_button_to_plus");
	}
});

});